package yawning.mew.gui.characters.glyphs;

import javax.swing.table.AbstractTableModel;

import yawning.mew.gui.tools.GlyphWrapper;

@SuppressWarnings("serial")
public class GlyphTableModel extends AbstractTableModel {
	private String[] columnNames = {"Selected", "Type", "Name", "Description"};
	private GlyphWrapper[] data;
	@SuppressWarnings("rawtypes")
	Class[] columnTypes = new Class[] {
			Boolean.class, String.class, String.class, String.class
		};
	
	boolean[] columnEditables = new boolean[] {
			true, false, false, false
		};
	public boolean isCellEditable(int row, int column) {
		return columnEditables[column];
	}
	public GlyphTableModel(GlyphWrapper[] data)
	{
		super();
		this.data = data;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Class getColumnClass(int columnIndex) {
		return columnTypes[columnIndex];
	}
	
	public String getColumnName(int index){
		return columnNames[index];
	}
	
	@Override
	public int getColumnCount() {
		return 4;
	}

	@Override
	public int getRowCount() {
		if(data == null)
			return 0;
		return data.length;
	}
	
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch(columnIndex)
		{
			case 0:
				return data[rowIndex].isSelected();
			case 1:
				return data[rowIndex].getTypeName();
			case 2:
				return data[rowIndex].getName();
			case 3:
				return data[rowIndex].getDescription();
		}
		return null;
	}

	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		if(columnIndex ==0)
		{
			if(aValue instanceof Boolean){
				super.setValueAt(data[rowIndex].setSelected((Boolean)aValue), rowIndex, columnIndex);
			}
		}else{
			super.setValueAt(aValue, rowIndex, columnIndex);
		}
	}
}
